<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>忘记密码</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/adminui/dist/css/admin.css}" media="all">
  <link rel="stylesheet" th:href="@{/adminui/dist/css/login.css}" media="all">
</head>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-forget" style="display: none;">
  <div class="layadmin-user-login-main">
    <div class="layadmin-user-login-box layadmin-user-login-header">
      <h2>忘记密码</h2>
      <p>通用后台管理系统</p>
    </div>
    <div class="layadmin-user-login-box layadmin-user-login-body layui-form">

      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
        <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="请输入登录用户名" class="layui-input" lay-affix="clear">
      </div>

      <!--通过注册手机号收取验证码方式-->
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="LAY-user-login-cellphone"></label>
        <input type="text" name="cellphone" id="LAY-user-login-cellphone" lay-verify="phone" placeholder="请输入注册时的手机号" class="layui-input" lay-affix="clear">
      </div>
      <div class="layui-form-item">
        <div class="layui-row">
          <div class="layui-col-xs7">
            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-smscode"></label>
            <input type="text" name="vercode" id="LAY-user-login-smscode" lay-verify="required" placeholder="短信验证码" class="layui-input" lay-affix="clear">
          </div>
          <div class="layui-col-xs5">
            <div style="margin-left: 10px;">
              <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="LAY-user-getsmscode">获取验证码</button>
            </div>
          </div>
        </div>
      </div>

      <!--图片验证码方式-->
<!--      <div class="layui-form-item">-->
<!--        <div class="layui-row">-->
<!--          <div class="layui-col-xs7">-->
<!--            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>-->
<!--            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input" lay-affix="clear">-->
<!--          </div>-->
<!--          <div class="layui-col-xs5">-->
<!--            <div style="margin-left: 10px;">-->
<!--              <img th:src="@{/captcha}" class="layadmin-user-login-codeimg" id="LAY-user-get-vercode" onclick="this.src=this.src+'?p='+Math.random()">-->
<!--            </div>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->

      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
        <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass" placeholder="新密码" class="layui-input" lay-affix="eye">
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
        <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码" class="layui-input" lay-affix="eye">
      </div>
      <div class="layui-form-item">
        <button class="layui-btn layui-btn-normal layui-btn-fluid" lay-submit lay-filter="LAY-user-forget-resetpass">重置新密码</button>
      </div>
    </div>
  </div>

  <div class="layui-trans layadmin-user-login-footer">

    <p>© 2023 <a href="www.llyong.cn" target="_blank">www.llyong.cn</a></p>

  </div>
</div>

<script th:src="@{/layui/layui.js}"></script>
<script>
  layui.config({
    base: '/' //静态资源所在路径
  }).use(['index'], function () {
    let $ = layui.$;
    let setter = layui.setter;
    let admin = layui.admin;
    let form = layui.form;

    form.render();

    //自定义验证
    form.verify({
      nickname: function (value, item) { //value：表单的值、item：表单的DOM对象
        if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
          return '用户名不能有特殊字符';
        }
        if (/(^\_)|(\__)|(\_+$)/.test(value)) {
          return '用户名首尾不能出现下划线\'_\'';
        }
        // if(/^\d+\d+\d$/.test(value)){
        //   return '用户名不能全为数字';
        // }
      }

      //我们既支持上述函数式的方式，也支持下述数组的形式
      //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
      , pass: [
        /^[\S]{6,12}$/
        , '密码必须6到12位，且不能出现空格'
      ]
    });

    //发送短信验证码
    admin.sendAuthCode({
      elem: '#LAY-user-getsmscode'
      , elemPhone: '#LAY-user-login-cellphone'
      , elemVercode: '#LAY-user-login-smscode'
    });

    //找回密码下一步
    // form.on('submit(LAY-user-forget-submit)', function (obj) {
    //   let field = obj.field;
    //
    //   //请求接口
    //   admin.req({
    //     url: layui.setter.paths.base + 'auth/valid/code' //实际使用请改成服务端真实接口
    //     , type: 'post'
    //     , data: field
    //     , done: function (res) {
    //       location.hash = '/type=resetpass';
    //       location.reload();
    //     }
    //   });
    //
    //   return false;
    // });

    //重置密码
    form.on('submit(LAY-user-forget-resetpass)', function (obj) {
      let field = obj.field;

      //确认密码
      if (field.password !== field.repass) {
        return layer.msg('两次密码输入不一致');
      }

      delete field.repass;

      //请求接口
      admin.req({
        url: layui.setter.paths.base + 'resetpass' //实际使用请改成服务端真实接口
        , type: 'post'
        , data: field
        , done: function (res) {
          layer.msg('密码已成功重置', {
            offset: '15px'
            , icon: 1
            , time: 1000
          }, function () {
            //跳转到登入页
            // location.href = '/login';
            window.top.location.href = '/login';
          });
        }
      });

      return false;
    });

  });
</script>
</body>
</html>